package ai.zixing.factory.schemes01.controller;

import ai.zixing.factory.schemes01.entity.AwardInfo;
import ai.zixing.factory.schemes01.entity.DiscountResult;
import ai.zixing.factory.schemes01.entity.SmallGiftInfo;
import ai.zixing.factory.schemes01.service.DiscountService;
import ai.zixing.factory.schemes01.service.SmallGiftService;
import ai.zixing.factory.schemes01.service.YouKuMemberService;

import java.util.UUID;

/**
 * 发放奖品接口
 */
public class DeliverController {

    /**
     * 按照类型的不同发放奖品
     *  奖品类型： 1打折券；2优酷会员；3小礼品
     * @param awardInfo
     */
    public void awardToUser(AwardInfo awardInfo) {
        if (awardInfo.getAwardTypes() == 1) {
            DiscountService discountService = new DiscountService();
            DiscountResult discountResult = discountService.sendDiscount(awardInfo.getUid(), awardInfo.getAwardNumber());
            System.out.println("发送打折券成功！ " + discountResult);
        } else if (awardInfo.getAwardTypes() == 2) {
            String phone = awardInfo.getExtMap().get("phone");
            YouKuMemberService service = new YouKuMemberService();
            service.openMember(phone, awardInfo.getAwardNumber());
            System.out.println("优酷会员发放成功");
        } else {
            // 封装收货人的信息
            SmallGiftInfo info = new SmallGiftInfo();
            info.setUserName(awardInfo.getExtMap().get("username"));
            info.setAddress(awardInfo.getExtMap().get("address"));
            info.setUserPhone(awardInfo.getExtMap().get("phone"));
            info.setOrderId(UUID.randomUUID().toString());
            SmallGiftService service = new SmallGiftService();
            Boolean aBoolean = service.giveSmallGift(info);
            if (aBoolean) {
                System.out.println("发放小礼品成功！");
            }
        }
    }
}
